<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  Control.Monad.Fail</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (C) 2015 David Luposchainsky,</span><span>
</span><span id="line-7"></span><span class="hs-comment">--                (C) 2015 Herbert Valerio Riedel</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Transitional module providing the 'MonadFail' class and primitive</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- instances.</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- This module can be imported for defining forward compatible</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- 'MonadFail' instances:</span><span>
</span><span id="line-19"></span><span class="hs-comment">--</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- import qualified Control.Monad.Fail as Fail</span><span>
</span><span id="line-22"></span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- instance Monad Foo where</span><span>
</span><span id="line-24"></span><span class="hs-comment">--   (&gt;&gt;=) = {- ...bind impl... -}</span><span>
</span><span id="line-25"></span><span class="hs-comment">--</span><span>
</span><span id="line-26"></span><span class="hs-comment">--   -- Provide legacy 'fail' implementation for when</span><span>
</span><span id="line-27"></span><span class="hs-comment">--   -- new-style MonadFail desugaring is not enabled.</span><span>
</span><span id="line-28"></span><span class="hs-comment">--   fail = Fail.fail</span><span>
</span><span id="line-29"></span><span class="hs-comment">--</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- instance Fail.MonadFail Foo where</span><span>
</span><span id="line-31"></span><span class="hs-comment">--   fail = {- ...fail implementation... -}</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-33"></span><span class="hs-comment">--</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- See &lt;https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail&gt;</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- for more details.</span><span>
</span><span id="line-36"></span><span class="hs-comment">--</span><span>
</span><span id="line-37"></span><span class="hs-comment">-- @since 4.9.0.0</span><span>
</span><span id="line-38"></span><span class="hs-comment">--</span><span>
</span><span id="line-39"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Control.Monad.Fail</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Control.Monad.Fail.html#MonadFail"><span class="hs-identifier">MonadFail</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Control.Monad.Fail.html#fail"><span class="hs-identifier">fail</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier">String</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#Monad"><span class="hs-identifier">Monad</span></a></span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier">Maybe</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier">Nothing</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier">IO</span></a></span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#failIO"><span class="hs-identifier">failIO</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- | When a value is bound in @do@-notation, the pattern on the left</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- hand side of @&lt;-@ might not match. In this case, this class</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- provides a function to recover.</span><span>
</span><span id="line-46"></span><span class="hs-comment">--</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- A 'Monad' without a 'MonadFail' instance may only be used in conjunction</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- with pattern that always match, such as newtypes, tuples, data types with</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- only a single data constructor, and irrefutable patterns (@~pat@).</span><span>
</span><span id="line-50"></span><span class="hs-comment">--</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- Instances of 'MonadFail' should satisfy the following law: @fail s@ should</span><span>
</span><span id="line-52"></span><span class="hs-comment">-- be a left zero for 'Control.Monad.&gt;&gt;=',</span><span>
</span><span id="line-53"></span><span class="hs-comment">--</span><span>
</span><span id="line-54"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- fail s &gt;&gt;= f  =  fail s</span><span>
</span><span id="line-56"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-57"></span><span class="hs-comment">--</span><span>
</span><span id="line-58"></span><span class="hs-comment">-- If your 'Monad' is also 'Control.Monad.MonadPlus', a popular definition is</span><span>
</span><span id="line-59"></span><span class="hs-comment">--</span><span>
</span><span id="line-60"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- fail _ = mzero</span><span>
</span><span id="line-62"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-63"></span><span class="hs-comment">--</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- @since 4.9.0.0</span><span>
</span><span id="line-65"></span><span class="hs-keyword">class</span><span> </span><span class="annot"><a href="GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679494438"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span id="MonadFail"><span class="annot"><a href="Control.Monad.Fail.html#MonadFail"><span class="hs-identifier hs-var">MonadFail</span></a></span></span><span> </span><span id="local-6989586621679494438"><span class="annot"><a href="#local-6989586621679494438"><span class="hs-identifier hs-type">m</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-66"></span><span>    </span><span id="local-6989586621679494437"><span id="fail"><span class="annot"><a href="Control.Monad.Fail.html#fail"><span class="hs-identifier hs-type">fail</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679494438"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679494437"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | @since 4.9.0.0</span><span>
</span><span id="line-70"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Control.Monad.Fail.html#MonadFail"><span class="hs-identifier hs-type">MonadFail</span></a></span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-71"></span><span>    </span><span id="local-6989586621679494424"><span class="annot"><span class="annottext">fail :: forall a. String -&gt; Maybe a
</span><a href="Control.Monad.Fail.html#fail"><span class="hs-identifier hs-var hs-var hs-var hs-var">fail</span></a></span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">-- | @since 4.9.0.0</span><span>
</span><span id="line-74"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Control.Monad.Fail.html#MonadFail"><span class="hs-identifier hs-type">MonadFail</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-75"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Control.Monad.Fail.html#fail"><span class="hs-pragma hs-type">fail</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-76"></span><span>    </span><span id="local-6989586621679494418"><span class="annot"><span class="annottext">fail :: forall a. String -&gt; [a]
</span><a href="Control.Monad.Fail.html#fail"><span class="hs-identifier hs-var hs-var hs-var hs-var">fail</span></a></span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span class="hs-comment">-- | @since 4.9.0.0</span><span>
</span><span id="line-79"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Control.Monad.Fail.html#MonadFail"><span class="hs-identifier hs-type">MonadFail</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-80"></span><span>    </span><span id="local-6989586621679494412"><span class="annot"><span class="annottext">fail :: forall a. String -&gt; IO a
</span><a href="Control.Monad.Fail.html#fail"><span class="hs-identifier hs-var hs-var hs-var hs-var">fail</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO a
forall a. String -&gt; IO a
</span><a href="GHC.Base.html#failIO"><span class="hs-identifier hs-var">failIO</span></a></span><span>
</span><span id="line-81"></span></pre></body></html>